package com.source.lightfowl.basedata.controller;

import com.source.lightfowl.basedata.entity.Barcode_Machine_Status;
import com.source.lightfowl.basedata.service.BarcodeMachineStatusService;
import com.source.lightfowl.utils.MyResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@Api(tags = "条码脚标机监控")
public class BarcodeMachineStatusController {
    @Autowired
    private BarcodeMachineStatusService barcodeMachineStatusService;

    //编辑条码机（测试通过）
    @ApiOperation(value = "编辑条码机")
    @PostMapping("/addBarcodeMachineStatus")
    public MyResult editBarcodeMachineStatus(Barcode_Machine_Status barcode_machine_status){
        try {
            barcodeMachineStatusService.editBarcodeMachineStatus(barcode_machine_status);
        }catch (Exception e) {
            e.printStackTrace();
            return MyResult.build(1, "编辑失败");
        }
        return MyResult.build(200, "编辑成功");

    }

    //查看条码机（测试通过）
    //11.4 版本修改  对数据排序 允许数据重复
    @ApiOperation(value = "查看条码机")
    @GetMapping("/findBarcodeMachineStatus")
    public List<Barcode_Machine_Status> FindBarcodeMachineStatus(){
        return barcodeMachineStatusService.findBarcodeMachineStatus();
    }

    @ApiOperation(value = "分页查询条码机")
    @GetMapping(value = "/allStatus/{page}/{size}")
    public MyResult findAllStatus(@PathVariable int page, @PathVariable int size){
        return MyResult.build(0, "查询成功",barcodeMachineStatusService.findPageStatus(page, size));
    }

    @ApiOperation(value = "回显条码机")
    @GetMapping("/findBarcodeMachineStatusById")
    public Barcode_Machine_Status FindBarcodeMachineStatusById(@RequestParam("id") String id){
        Barcode_Machine_Status barcode_machine_status= barcodeMachineStatusService.findBarcodeMachineStatusById(id);
        return barcode_machine_status;
    }

    @ApiOperation(value = "回显条码机by MachineId")
    @GetMapping("/findBarcodeMachineStatusByMachineId")
    public Barcode_Machine_Status FindBarcodeMachineStatusByMachineId(@RequestParam("id") String id){
        Barcode_Machine_Status barcode_machine_status= barcodeMachineStatusService.findBarcodeMachineStatusById(id);
        return barcode_machine_status;
    }

    //删除条形码机（测试通过）
    @ApiOperation(value = "删除条形码机")
    @DeleteMapping("/deleteBarcodeMachineStatus")
    public MyResult DeleteBarcodeMachineStatus(@RequestParam("id")  String id){
        try {
            barcodeMachineStatusService.deleteBarcodeMachineStatus(id);
        } catch (Exception e) {
            e.printStackTrace();
            return MyResult.build(1, "删除失败");
        }
        return MyResult.build(200, "删除成功");
    }
}
